#version 130

in vec2 TexCoord;
in vec3 LightDirection;
in vec3 EyeDirection;
in vec3 Normal;
in vec3 VertPos;

uniform sampler2D TexDiffuse;

void main (void)  
{ 
  vec3 fvLightDirection = normalize(LightDirection);
  vec3 fvNormal = normalize(Normal);
  float fNDotL = dot( fvNormal, fvLightDirection );
  
  vec3 fvReflection     = normalize( ( ( 2.0 * fvNormal ) * fNDotL ) - fvLightDirection ); 
  vec3 fvViewDirection 	= normalize(EyeDirection);
  float fRDotV           = max( 0.0, dot( fvReflection, fvViewDirection ) );

  vec4  fvBaseColor      =  vec4(texture2D(TexDiffuse, TexCoord));
  //vec4  fvBaseColor      =  vec4(texture2D(TexDiffuse, TexCoord.yx));

  vec4  fvTotalAmbient   = vec4(0.2, 0.2, 0.2, 0.0); 
  vec4  fvTotalDiffuse   = fNDotL * fvBaseColor; 
  vec4  fvTotalSpecular  = vec4(1,1,1,1) * ( pow( fRDotV, 25 ) );
  
  gl_FragColor = fvTotalAmbient + fvTotalDiffuse; // + fvTotalSpecular;
  //gl_FragColor = vec4(TexCoord.xy, 0, 0);
  //gl_FragColor = vec4(VertPos, 0);
}  